package com.seashop.response;

import com.seashop.enums.ResponseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author moredln
 * @desc 返回类封装
 * @date 2020-07-10 22:44
 */
@Data
@ApiModel(value = "基础返回")
public class ResponseBase<T> {

    @ApiModelProperty(value = "状态码")
    private Integer code;

    @ApiModelProperty(value = "提示信息")
    private String msg;

    @ApiModelProperty(value = "具体内容")
    private T data;

    public ResponseBase() {

    }

    public ResponseBase(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseBase(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseBase<T> success() {
        return success(null);
    }

    public static <T> ResponseBase<T> success(T data) {
        return new <T>ResponseBase<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), data);
    }

    public static <T> ResponseBase<T> fail() {
        return fail(null);
    }

    public static <T> ResponseBase<T> fail(String msg) {
        return fail(ResponseEnum.FAIL.getCode(), msg, null);
    }

    public static <T> ResponseBase<T> fail(T data) {
        return fail(ResponseEnum.FAIL.getCode(), ResponseEnum.FAIL.getMsg(), data);
    }

    public static <T> ResponseBase<T> fail(Integer code, String msg) {
        return fail(code, msg, null);
    }

    public static <T> ResponseBase<T> fail(Integer code, String msg, T data) {
        return new <T>ResponseBase<T>(code, msg, data);
    }

    public static <T> ResponseBase<T> error() {
        return error(null);
    }

    public static <T> ResponseBase<T> error(T data) {
        return error(ResponseEnum.SERVER_ERROR.getCode(), ResponseEnum.SERVER_ERROR.getMsg(), data);
    }

    public static <T> ResponseBase<T> error(Integer code, String msg) {
        return error(code, msg, null);
    }

    public static <T> ResponseBase<T> error(Integer code, String msg, T data) {
        return new <T>ResponseBase<T>(code, msg, data);
    }

}
